package com.example.demo.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class userAspect {


    /**
     * 配置切点,拦截规则
     */
    @Pointcut("execution(* com.example.demo.controller.*.* (..))")
    public void pointcut()
    {
        //一对多
    }

    @Before("pointcut()")
    public  void BeforeAdvice()
    {
        System.out.println("执行前置方法");
    }


    @After("pointcut()")
    public  void AfterAdvice()
    {
        System.out.println("执行后置方法");
    }

    // return 之前通知
    @AfterReturning("pointcut()")
    public void doAfterReturning(){
        System.out.println("执⾏ AfterReturning ⽅法");
    }
    // 抛出异常之前通知
    @AfterThrowing("pointcut()")
    public void doAfterThrowing(){
        System.out.println("执⾏ doAfterThrowing ⽅法");
    }

    @Around("pointcut()")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint)
    {
        Object obj=null;
        System.out.println("Around ⽅法开始执⾏");
        try {
            obj=joinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("Around ⽅法结束执⾏");
        return obj;
    }

}
